<?php

namespace App\Enums\Check;

class CheckEnum
{
    const CHECK_STATUS_INIT    = 1;
    const CHECK_STATUS_SUCCESS = 2;
    const CHECK_STATUS_AUDIT   = 3;
    const CHECK_STATUS_ERROR   = 4;

    const CHECK_STATUS_TEXT = [
        self::CHECK_STATUS_INIT    => '未对账', // 初始化
        self::CHECK_STATUS_SUCCESS => '正常',
        self::CHECK_STATUS_AUDIT   => '待审核',
        self::CHECK_STATUS_ERROR   => '异常',
    ];

    // 支付业务类型
    const SYS_TYPE_RMS_MEAL            = 1; // RMS餐饮
    const SYS_TYPE_ROS                 = 2; // 商家app订货
    const SYS_TYPE_RMS_COUPON_PACKAGE  = 3; // RMS券包
    const SYS_TYPE_OPEN_SHOP_LEAGUE    = 4; // 开店加盟
    const SYS_TYPE_OPEN_SHOP_DESIGN    = 5; // 设计费
    const SYS_TYPE_OPEN_SHOP_EQUIPMENT = 6; // 设备费
    const SYS_TYPE_OPEN_SHOP_DECORATE  = 7; // 软装费
    const SYS_TYPE_ANNUAL_FEE          = 8; // 数字化管理年费
    const SYS_TYPE_AGAINST             = 9; // 违约函
    const SYS_TYPE_WORK_CLOTHES        = 10; // 工服

    const SYS_TYPE_TEXT = [
        self::SYS_TYPE_RMS_MEAL            => 'RMS餐饮',
        self::SYS_TYPE_ROS                 => '商家app订货',
        self::SYS_TYPE_RMS_COUPON_PACKAGE  => 'RMS券包',
        self::SYS_TYPE_OPEN_SHOP_LEAGUE    => '开店加盟',
        self::SYS_TYPE_OPEN_SHOP_DESIGN    => '开店设计费',
        self::SYS_TYPE_OPEN_SHOP_EQUIPMENT => '开店设备费',
        self::SYS_TYPE_OPEN_SHOP_DECORATE  => '开店软装费',
        self::SYS_TYPE_ANNUAL_FEE          => '数字化管理年费',
        self::SYS_TYPE_AGAINST             => '加盟商违约金',
        self::SYS_TYPE_WORK_CLOTHES        => '商家工服订购',
    ];

    // 要对账的sys_type
    const CHECK_SYS_TYPES = [
        self::SYS_TYPE_OPEN_SHOP_LEAGUE,
        self::SYS_TYPE_OPEN_SHOP_DESIGN,
        self::SYS_TYPE_OPEN_SHOP_EQUIPMENT,
        self::SYS_TYPE_OPEN_SHOP_DECORATE,
        self::SYS_TYPE_ANNUAL_FEE,
        self::SYS_TYPE_AGAINST,
        self::SYS_TYPE_WORK_CLOTHES,
    ];

    // 支付方式
    const PAY_ACTION_NULL = 0; // 默认
//    const PAY_ACTION_SCAN   = 1; // 用户主扫（扫码支付）
    const PAY_ACTION_QRCODE = 2; // 用户被扫（二维码支付）
    const PAY_ACTION_MINI   = 3; // 小程序支付
    const PAY_ACTION_APP    = 5; // app支付
    const PAY_ACTION_WAP    = 6; // H5支付

    const PAY_ACTION_TEXT = [
        self::PAY_ACTION_NULL   => '全部',
//        self::PAY_ACTION_SCAN   => '用户主扫',
        self::PAY_ACTION_QRCODE => '被扫',
        self::PAY_ACTION_MINI   => '小程序支付',
        self::PAY_ACTION_APP    => 'APP支付',
        self::PAY_ACTION_WAP    => 'H5支付',
    ];

    // 支付直连渠道
    const PAY_CHANNEL_NULL = 0; // 默认
    const PAY_CHANNEL_ALI  = 1; // 支付宝
    const PAY_CHANNEL_WX   = 2; // 微信
    const PAY_CHANNEL_CASH = 3; // 现金
    const PAY_CHANNEL_FY   = 4; // 富友
    const PAY_CHANNEL_BANK = 5; // 银行转账
    const PAY_CHANNEL_MYBANK = 6; // 网商支付
//    const PAY_CHANNEL_POST_SALE     = 7; // 订货用-售后支付
//    const PAY_CHANNEL_UNION_PAY     = 8; // 银联,云闪付
    const PAY_CHANNEL_MYBANK_CASHIER_PAY  = 9; // 网商小程序支付

    // channel >= 100 都为自定义支付
    const PAY_CHANNEL_CUSTOM_PAYMENT = 100;

    const PAY_CHANNEL_TEXT = [
        self::PAY_CHANNEL_ALI                => '支付宝',
        self::PAY_CHANNEL_WX                 => '微信',
        self::PAY_CHANNEL_CASH               => '现金',
        self::PAY_CHANNEL_FY                 => '富友',
        self::PAY_CHANNEL_BANK               => '银行转账',
        self::PAY_CHANNEL_MYBANK             => '网商支付',
        self::PAY_CHANNEL_MYBANK_CASHIER_PAY => '网商小程序支付',
    ];

    const STAT_TYPE_STREAM = 1; // 按流水统计
    const STAT_TYPE_DAY    = 2; //  按天统计

    // 支付账号 - 公司户
    const COMPANY_TJ_SUPPLER_CHAIN = 1; // 天津供应链
    const COMPANY_FRIED_IDEA       = 2; // 心有炸念
    const COMPANY_DIGITAL_TECH     = 3; // 上海万皮思数字科技
    const COMPANY_ALI_SAND         = 4; // 支付宝沙箱
    const COMPANY_HN_FRUIT         = 5; // 河南干果店
    const COMPANY_FOOD_TECH        = 6; // 北京万皮思食品科技-富有

    const COMPANY_ACCOUNT = [
        self::COMPANY_TJ_SUPPLER_CHAIN => ['280488200238', '厦门万皮思供应链管理有限公司'],
        self::COMPANY_FRIED_IDEA       => ['110939648910401', '厦门心有炸念餐饮管理有限公司'],
    ];

    /**
     * 线下支付，银行账号
     * @param int $sysType
     * @return array
     */
    public static function getBankCompany(int $sysType, int $timestamp = 0): array
    {
        if (!$timestamp) {
            $timestamp = time();
        }

        switch ($sysType) {
            case CheckEnum::SYS_TYPE_OPEN_SHOP_LEAGUE:
            case CheckEnum::SYS_TYPE_ANNUAL_FEE:
            case CheckEnum::SYS_TYPE_AGAINST:
                $company = CheckEnum::COMPANY_FRIED_IDEA;
                break;

            case CheckEnum::SYS_TYPE_OPEN_SHOP_DESIGN:
                if ($timestamp >= 1655428500) {
                    $company = CheckEnum::COMPANY_FRIED_IDEA;
                    break;
                } else {
                    $company = CheckEnum::COMPANY_TJ_SUPPLER_CHAIN;
                }
                break;

            case CheckEnum::SYS_TYPE_OPEN_SHOP_EQUIPMENT:
            case CheckEnum::SYS_TYPE_OPEN_SHOP_DECORATE:
                $company = CheckEnum::COMPANY_TJ_SUPPLER_CHAIN;
                break;
            default:
                $company = 0;
        }

        $companyAccount = self::COMPANY_ACCOUNT[$company][0] ?? '';
        $companyName    = self::COMPANY_ACCOUNT[$company][1] ?? '';

        return [$company, $companyAccount, $companyName];
    }

    /**
     * api用枚举
     * @return array[]
     */
    public static function apiEnums(): array
    {
        return [
            [
                'field'   => 'sysType',
                'text'    => '订单类型',
                'options' => (object)[
                    0                                  => '全部',
                    self::SYS_TYPE_OPEN_SHOP_LEAGUE    => self::SYS_TYPE_TEXT[self::SYS_TYPE_OPEN_SHOP_LEAGUE],
                    self::SYS_TYPE_OPEN_SHOP_DESIGN    => self::SYS_TYPE_TEXT[self::SYS_TYPE_OPEN_SHOP_DESIGN],
                    self::SYS_TYPE_OPEN_SHOP_EQUIPMENT => self::SYS_TYPE_TEXT[self::SYS_TYPE_OPEN_SHOP_EQUIPMENT],
                    self::SYS_TYPE_OPEN_SHOP_DECORATE  => self::SYS_TYPE_TEXT[self::SYS_TYPE_OPEN_SHOP_DECORATE],
                    self::SYS_TYPE_ANNUAL_FEE          => self::SYS_TYPE_TEXT[self::SYS_TYPE_ANNUAL_FEE],
                ]
            ],
            [
                'field'   => 'payChannel',
                'text'    => '支付渠道',
                'options' => (object)array_merge([0 => '全部'], self::PAY_CHANNEL_TEXT),
            ],
            [
                'field'   => 'payAction',
                'text'    => '付款类型',
                'options' => (object)self::PAY_ACTION_TEXT
            ],
            [
                'field'   => 'checkStatus',
                'text'    => '对账状态',
                'options' => (object)array_merge([0 => '全部'], self::CHECK_STATUS_TEXT),
            ],
        ];
    }
}
